Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/layers/LayerOpacity.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 3.17 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.map.layers

T8b949e/**
* Per-layer opacity, keyed the way each kind of layer is already identified elsewhere.
*
* Two key spaces share one map because they cannot collide: a built-in overlay is keyed by its catalogue id
* (`hillshade`), an imported layer by its URI. The URI — not the id — is deliberate: a file-backed [MapLayerItem] gets
* a fresh random id on every load, so an id key would lose the user's setting at the next start. `hiddenLayerUrls` keys
* visibility the same way for the same reason.
*
* Stored as a `stringSet` preference of `key|:|value` entries, matching how `networkMapLayers` encodes its records —
* DataStore has no map type.
*/
Tff7b72const Tff7b72val Te6edf3LAYER_OPACITY_OPAQUETb4b4b4: Tffa657Float Tff7b72= T79c0ff1f

Tff7b72private Tff7b72const Tff7b72val Te6edf3OPACITY_DELIMITER Tff7b72= Ta5d6ff"Ta5d6ff|:|Ta5d6ff"

T8b949e/** This layer's opacity, or fully opaque when the user has never moved its slider. */
Tff7b72fun Td2a8ffMapTff7b72<Tffa657StringTb4b4b4, Tffa657FloatTff7b72>Tb4b4b4.Te6edf3opacityOfTb4b4b4(Te6edf3keyTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657Float Tff7b72= Tff7b72thisTff7b72[Te6edf3keyTff7b72] Tff7b72?: Te6edf3LAYER_OPACITY_OPAQUE

T8b949e/**
* Encodes for storage, dropping every fully-opaque layer.
*
* Opaque is the default, so persisting it would add an entry for each layer the user ever touched and never remove one
* — the set would only ever grow, including for layers long since deleted.
*/
Tff7b72fun Td2a8ffencodeLayerOpacityTb4b4b4(Te6edf3opacitiesTb4b4b4: Te6edf3MapTff7b72<Tffa657StringTb4b4b4, Tffa657FloatTff7b72>Tb4b4b4)Tb4b4b4: Te6edf3SetTff7b72<Tffa657StringTff7b72> Tff7b72= Te6edf3opacities
Tb4b4b4.Te6edf3filterValues Tb4b4b4{ Tffa657it Tff7b72< Te6edf3LAYER_OPACITY_OPAQUE Tb4b4b4}
Tb4b4b4.Te6edf3mapToTb4b4b4(Te6edf3mutableSetOfTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{ Tb4b4b4(Te6edf3keyTb4b4b4, Te6edf3opacityTb4b4b4) Tff7b72-Tff7b72>
Ta5d6ff"Tffd700$Te6edf3keyTffd700$Te6edf3OPACITY_DELIMITERTffd700${Te6edf3opacityTb4b4b4.Te6edf3coerceInTb4b4b4(T79c0ff0fTb4b4b4, Te6edf3LAYER_OPACITY_OPAQUETb4b4b4)Tffd700}Ta5d6ff"
Tb4b4b4}

T8b949e/**
* Decodes stored entries, dropping any that no longer parse.
*
* Split from the *last* delimiter: a key is an imported layer's URI, built from a user-chosen file name, so it may
* contain the delimiter itself. The value never can.
*/
Tff7b72fun Td2a8ffdecodeLayerOpacityTb4b4b4(Te6edf3entriesTb4b4b4: Te6edf3SetTff7b72<Tffa657StringTff7b72>Tb4b4b4)Tb4b4b4: Te6edf3MapTff7b72<Tffa657StringTb4b4b4, Tffa657FloatTff7b72> Tff7b72= Te6edf3entries
Tb4b4b4.Te6edf3mapNotNull Tb4b4b4{ Te6edf3entry Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3entryTb4b4b4.Te6edf3containsTb4b4b4(Te6edf3OPACITY_DELIMITERTb4b4b4)Tb4b4b4) Tff7b72returnTf0883e@mapNotNull Tff7b72null
Tff7b72val Te6edf3key Tff7b72= Te6edf3entryTb4b4b4.Te6edf3substringBeforeLastTb4b4b4(Te6edf3OPACITY_DELIMITERTb4b4b4)Tb4b4b4.Te6edf3takeIf Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3isNotEmptyTb4b4b4(Tb4b4b4) Tb4b4b4} Tff7b72?: Tff7b72returnTf0883e@mapNotNull Tff7b72null
T8b949e// isFinite, not merely parseable: "NaN" parses, and coerceIn cannot clamp it because every comparison
T8b949e// against NaN is false — so a corrupted entry would reach the renderers as a non-finite opacity.
Tff7b72val Te6edf3opacity Tff7b72=
Te6edf3entryTb4b4b4.Te6edf3substringAfterLastTb4b4b4(Te6edf3OPACITY_DELIMITERTb4b4b4)Tb4b4b4.Te6edf3toFloatOrNullTb4b4b4(Tb4b4b4)Tff7b72?.Te6edf3takeIf Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3isFiniteTb4b4b4(Tb4b4b4) Tb4b4b4}
Tff7b72?: Tff7b72returnTf0883e@mapNotNull Tff7b72null
Te6edf3key Te6edf3to Te6edf3opacityTb4b4b4.Te6edf3coerceInTb4b4b4(T79c0ff0fTb4b4b4, Te6edf3LAYER_OPACITY_OPAQUETb4b4b4)
Tb4b4b4}
Tb4b4b4.Te6edf3toMapTb4b4b4(Tb4b4b4)

Served by rngit 1.5.2 - Generated in 0.12s